package com.logicalthinking.socialmall.service.impl;

import com.github.chenlijia1111.commonModule.common.pojo.CommonMallConstants;
import com.github.chenlijia1111.commonModule.dao.*;
import com.github.chenlijia1111.utils.list.Lists;
import com.logicalthinking.socialmall.common.vo.requestVo.product.AdminProductQueryParams;
import com.logicalthinking.socialmall.common.vo.requestVo.product.AppProductQueryParams;
import com.logicalthinking.socialmall.common.vo.responseVo.product.AdminProductListVo;
import com.logicalthinking.socialmall.common.vo.responseVo.product.AppProductListVo;
import com.logicalthinking.socialmall.common.vo.responseVo.product.SocialAppProductVo;
import com.logicalthinking.socialmall.dao.SocialProductMapper;
import com.logicalthinking.socialmall.service.SocialProductServiceI;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品表
 *
 * @author chenLiJia
 * @since 2019-11-01 13:46:54
 **/
@Service(CommonMallConstants.BEAN_SUFFIX + "SocialProductServiceI")
public class ProductServiceImpl implements SocialProductServiceI {


    @Resource
    private ProductMapper productMapper;//产品
    @Resource
    private SocialProductMapper socialProductMapper;//产品
    @Resource
    private GoodsMapper goodsMapper;//商品
    @Resource
    private ProductSpecMapper productSpecMapper;
    @Resource
    private ProductSpecValueMapper productSpecValueMapper;//产品规格值
    @Resource
    private GoodSpecMapper goodSpecMapper;//商品规格
    @Resource
    private ShoppingOrderMapper shoppingOrderMapper;//订单


    /**
     * 客户端通过产品Id查询产品详情
     * @param productId
     * @return
     */
    @Override
    public SocialAppProductVo appFindById(String productId) {
        //判断是否存在
        return null;
    }

    /**
     * 客户端查询商品列表
     *
     * @param params
     * @return
     */
    @Override
    public List<AppProductListVo> appListPage(AppProductQueryParams params) {
        List<AppProductListVo> list = socialProductMapper.appListPage(params);
        //计算距离
        if (Lists.isNotEmpty(list)) {
            for (AppProductListVo vo : list) {
                vo.calculateDistance(params.getUserLongitude(), params.getUserLatitude());
            }
        }
        return list;
    }

    /**
     * 后台查询商品列表
     *
     * @param params
     * @return
     */
    @Override
    public List<AdminProductListVo> adminListPage(AdminProductQueryParams params) {
        List<AdminProductListVo> list = socialProductMapper.adminListPage(params);
        if (Lists.isNotEmpty(list)) {
            for (AdminProductListVo vo : list) {
                //生成交易类型名称
                vo.createTransactionTypeName();
            }
        }
        return list;
    }
}
